from langgraph_memory.src.graph.graph import graph
from uuid import uuid4

def run_conversation(user_id: str, thread_id: str, user_input: str):
    config = {"configurable": {"thread_id": thread_id, "user_id": user_id}}

    print(f"\n💬 User: {user_input}")
    for event in graph.stream(
        {"messages": [{"role": "user", "content": user_input}]},
        config,
        stream_mode="updates"
    ):
        for node_name, node_state in event.items():
            if "messages" in node_state:
                last_msg = node_state["messages"][-1]
                print("last_msg:", last_msg)
                print(f"🤖 Assistant: {last_msg.content}")

if __name__ == "__main__":
    USER_ID = "user_123"
    THREAD_1 = str(uuid4())
    THREAD_2 = str(uuid4())

    run_conversation(USER_ID, THREAD_1, "你好，我喜欢披萨!")
    run_conversation(USER_ID, THREAD_1, "我最爱的食物是什么?")
    run_conversation(USER_ID, THREAD_2, "我最近告诉过你什么吗?")

    # 换个用户
    USER_ID_2 = "user_456"
    run_conversation(USER_ID_2, str(uuid4()), "我不喜欢吃甜食")
    run_conversation(USER_ID_2, str(uuid4()), "我不喜欢啥")